import abc
from typing import Generic, Iterator, TypeVar


class DetachedJob(abc.ABC):
    @property
    @abc.abstractmethod
    def id(self) -> str:
        pass

    @abc.abstractmethod
    def monitor(self):
        pass

    @property
    @abc.abstractmethod
    def active(self) -> bool:
        pass

    @abc.abstractmethod
    def terminate(self):
        pass


C = TypeVar('C')
P = TypeVar('P')
J = TypeVar('J', bound=DetachedJob)


class DetachedJobsPlatform(Generic[C, P, J], abc.ABC):
    @abc.abstractmethod
    def new_detached_job(self, config: C, plan: P) -> J:
        pass

    @abc.abstractmethod
    def get_detached_job(self, job_id: str) -> J | None:
        pass

    @abc.abstractmethod
    def iter_detached_jobs(self) -> Iterator[J]:
        pass
